package bubbleFishBob.gameobjects;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.zip.DataFormatException;

import com.golden.gamedev.Game;
import com.golden.gamedev.object.AnimatedSprite;

public abstract class AbstractGameObject extends AnimatedSprite
{

    protected Game myGame;
    protected BufferedImage[] animationImages;

    public AbstractGameObject(Game game)
    {
        myGame = game;
    }

    public AbstractGameObject(Game game, File file)
    {
        this(game);
        try
        {
            this.readAndSetImages(file);
        }
        catch (DataFormatException e)
        {
            e.printStackTrace();
        }
    }

    /**
     * Reads in images for sprite
     * 
     * @param fileLocation
     *            , directory of images to be used
     * @throws DataFormatException
     */
    protected void readAndSetImages(File fileLocation)
            throws DataFormatException
    {
        if (fileLocation.isDirectory())
        {
            animationImages = new BufferedImage[fileLocation.listFiles().length];
            int count = 0;
            for (File file : fileLocation.listFiles())
            {
                animationImages[count] = myGame
                        .getImage(file.getAbsolutePath());
                count++;
            }
            this.setImages(animationImages);
        }
        else
        {
            throw new DataFormatException(
                    "Incorrect file location, must be a directory");
        }
    }

    /**
     * Handles specific user inputs
     */
    protected abstract void handleUserInput(long elapsedTime);
}
